<?php if(!IS_AJAX){?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>许愿墙</title>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Intesys/AdminX/js/Wishingwall/css/fancybox.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Intesys/AdminX/js/Wishingwall/css/index.css">
</head>

<body><div class="add">
            <a href="<?php echo U('add');?>" id="fancy" class="add_note"></a>
        </div>
        <div class="container"style="position: relative">
        
        
        <?php }?>
            <?php foreach($list as $key => $row){list($left, $top, $zindex) = explode('|', $row['xyz']); ?>
        
        <dl class="paper a<?php echo $row['color'];?>"  style="left:<?php echo $left;?>px;top:<?php echo $top;?>px;z-index:<?php echo $row['id'];?>" data-id="<?php echo $row['id'];?>">
<dt>
<span class="username"><?php echo $row['name'];?></span>

</dt>
<dd class="content"><img style="float:left; margin-bottom:2px; margin-right:10px;" src="<?php echo $row['headimg'];?>" width="35"><?php echo $row['content'];?></dd>
<dd class="bottom">
<span class="time"><?php echo getEvaluateTime($row['addtime']);?></span>
<a class="close" href="javascript:void(0);"></a>
</dd>
</dl>

<?php }?> 


<?php if(!IS_AJAX){?> 
        </div>

        <script type="text/javascript" src="http://www.sucaihuo.com/Public/js/other/jquery.js"></script> 
        <script type='text/javascript' src='__PUBLIC__/Intesys/AdminX/js/Wishingwall/js/jquery-ui.min.js'></script>
        <script type="text/javascript" src="__PUBLIC__/Intesys/AdminX/js/Wishingwall/js/jquery.fancybox-1.3.1.pack.js"></script>
        <script type="text/javascript">
        // JavaScript Document
$(function() {
    var tmp;
    $('.paper').each(function() {
        tmp = $(this).css('z-index');
        if (tmp > zIndex)
            zIndex = tmp;
    })

    make_draggable($('dl'));

    $("#fancy").fancybox({
        'type': 'ajax',
        'modal': true,
        'titleShow': false,
    });

    $("#color li").live('click', function() {
        $(this).addClass("current").siblings().removeClass("current");
    });

    $("#addbtn").live('click', function(e) {
        var txt = $("#content").val();
        var username = $("#username").val();
        if (txt == "") {
            $("#content").focus();
            return false;
        }
        if (username == "") {
            $("#msg").html("请输入您的姓名！");
            $("#user").focus();
            return false;
        }
        var left = 0;
        var top = 0;
        var color_id = $("#color").children("li.current").attr("data-color-id");
        var data = {
            'zIndex': ++zIndex,
            'content': txt,
            'user': username,
            'left': left,
            'top': top,
            "color_id": color_id,
			"__hash__": $('[name="__hash__"]').eq(0).val()
        };
		
		
		
		
		
        $.post('<?php echo U('insert');?>', data, function(msg) {
            zIndex = zIndex++;
            if ($(msg.tbody).children().length > 0) {
                var str = msg.tbody;
                $(".container").append(str);
                make_draggable($('dl'));
                $.fancybox.close();
            } else {
                alert('error');
            }
        }, 'json');
        e.preventDefault();
    });
    $("#box_close").live('click', function(e) {
        $.fancybox.close();
    });
    $(".close").live('click', function(e) {
		if(!confirm('确定要删除吗？')){
			return false;
		}
        var obj_close = $(this);
        var id = obj_close.parents("dl").attr("data-id");
        $.get("<?php echo U('delete');?>", {id: id}, function(data) {
            if (data.status == 1) {
                obj_close.parents("dl").fadeOut(50);
            }
        }, "json")
    });
});

var zIndex = 0;
function make_draggable(elements) {
    elements.draggable({
        handle: 'dt', //拖动把手
        opacity: 0.8,
        containment: 'parent', //拖动范围 
        start: function(e, ui) {
            ui.helper.css('z-index', ++zIndex)
        },
        stop: function(e, ui) {
            $.get('<?php echo U('update_position');?>', {
                x: ui.position.left,
                y: ui.position.top,
                z: zIndex,
                id: parseInt(ui.helper.attr("data-id"))
            });
        }
    });
}
        </script>
        
        <style>
		     .content *{vertical-align:middle;}
		</style>
</body>
</html><?php }?>
